package com.ruoyi.server.thread;

import com.ruoyi.server.enums.CmdConstants;
import com.ruoyi.server.handler.ReceiptReader;
import com.ruoyi.server.pkg.SendMsg;
import com.ruoyi.server.read.BaseCenterReader;
import com.ruoyi.server.read.PrivateReader;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.Future;

/**
 *  消息回执器
 *
 * @author OpenACloud
 * @create 2024/6/5 11:49
 */
public class ReadReceiptReader extends ReceiptReader{

    private SendMsg sendMsg;
    private BaseCenterReader baseCenterReader;

    public ReadReceiptReader(){

    }

    public ReadReceiptReader(BaseCenterReader baseCenterReader, SendMsg sendMsg){
        this.sendMsg = sendMsg;
        this.baseCenterReader = baseCenterReader;
    }

    @Override
    public void operationComplete(Future future) throws Exception {
        this.sendMsg.STATUS = CmdConstants.READ_STATUS_FAIL;
        if(future.isSuccess()) {
            this.sendMsg.STATUS = CmdConstants.READ_STATUS_SUCCESS;
        }
        run();
    }

    @Override
    public void run() {
        baseCenterReader.saveMessages(sendMsg);
    }
}
